<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admin
 *
 * @author QUYET
 */
class Admin extends Admin_Controller {
    //put your code here
    public function __construct() {
        parent::__construct();
    }
    function index(){
        redirect('admin/about-us');
    }
    
    function change_language($lang='fr'){
        if($lang=='fr'){
            $this->session->set_userdata('lang','fr');
        }else{
            $this->session->set_userdata('lang','en');
        }
        $desination = $this->session->userdata('current_url')!=NULL?$this->session->userdata('current_url'):  base_url().'admin';
        redirect($desination);
    }
    
    function my_profile(){
        if($this->phpsession->get('user_id')){
            $this->load->library('form_validation');
            $this->load->database();
            if($one_rows = $this->db->get_where('account',array('id'=>$this->phpsession->get('user_id')))->row())
            {
                if(count($_POST)>=3){
                    $this->form_validation->set_rules('email', __('email'), 'trim|required|max_length[300]|xss_clean|valid_email');
                    //$this->form_validation->set_rules('password', __('admin_password'), 'trim|required|max_length[60]|xss_clean');
                    $this->form_validation->set_rules('fullname', __('admin_fullname'), 'trim|required|max_length[300]|xss_clean');
                    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
                    
                    if ($this->form_validation->run()) {
                        $record = array();
                        $record['email'] = $_POST['email'];
                        $record['fullname'] = $_POST['fullname'];
                        if(!empty($_POST['password'])) $record['password'] = trim(md5($this->input->post('password')));
                        $this->db->update('account',$record,array('id'=>$this->phpsession->get('user_id')));
                        $this->_data['errors'] = '<div class="error">'.__('admin_profile_updated').'</div>';
                        //redirect('admin/my_profile');
                    }
                    else $this->_data['errors'] = validation_errors();
                }
                else{
                    $_POST['email'] = $one_rows->email;
                    $_POST['fullname'] = $one_rows->fullname;
                }
                $this->display_admin('admin/my_profile');
            }            
            
        }
        else redirect('admin/about-us');        
    }
}

?>
